package com.ruoyi.business.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RescueRabbitConfig {

    // 正常交换机和队列
    @Bean
    public Exchange rescueTaskExchange() {
        return ExchangeBuilder.topicExchange("rescue_task_exchange").durable(true).build();
    }

    @Bean
    public Queue rescueTaskQueue() {
        return QueueBuilder.durable("rescue_task_queue")
                .deadLetterExchange("rescue_dlx_exchange")
                .deadLetterRoutingKey("rescue.dlx")
                .ttl(30 * 60 * 1000) // 30分钟过期时间
                .build();
    }

    @Bean
    public Binding bindingRescueTask() {
        return BindingBuilder.bind(rescueTaskQueue()).to(rescueTaskExchange()).with("rescue.task.#").noargs();
    }

    // 死信交换机和队列
    @Bean
    public Exchange rescueDlxExchange() {
        return ExchangeBuilder.topicExchange("rescue_dlx_exchange").durable(true).build();
    }

    @Bean
    public Queue rescueDlxQueue() {
        return QueueBuilder.durable("rescue_dlx_queue").build();
    }

    @Bean
    public Binding bindingRescueDlx() {
        return BindingBuilder.bind(rescueDlxQueue()).to(rescueDlxExchange()).with("rescue.dlx.#").noargs();
    }
}